package com.zhongxi.guoyuan.view;

import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.base.BaseActivity;

public class AdActivity extends BaseActivity implements View.OnClickListener {

    private WebView webView;
//    private String url;

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.activity_ad);
        initTitle();
        tvTitle.setText("广告");
        String url = getIntent().getStringExtra("url");

        webView = (WebView) findViewById(R.id.webView);

        // 设置WebView属性，能够执行Javascript脚本
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAppCacheEnabled(false);

        webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setDefaultTextEncodingName("UTF-8");
        webView.getSettings().setLoadWithOverviewMode(true);
//		my_webView.getSettings().setUseWideViewPort(true);

        // 加载需要显示的网页
        webView.loadUrl(url);
        // 设置Web视图
        webView.setWebViewClient(new HelloWebViewClient());
    }

    // Web视图
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        ivBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ivBack:
                finish();
                break;
        }
    }
}
